package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.mapper.CheckItemMapper;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.apache.dubbo.config.annotation.Service;

import java.util.List;

/**
 * @author ：yuanjian
 * @date ：Created in 2020/11/10 11:55
 * @description：
 */
@Service
public class CheckItemServiceImpl extends ServiceImpl<CheckItemMapper, CheckItem> implements CheckItemService {
    /*@Override
    public PageResult findPageByName(QueryPageBean pageBean) {
        IPage<CheckItem> page = page(new Page<>(pageBean.getCurrentPage(), pageBean.getPageSize()), new QueryWrapper<CheckItem>().eq("is_delete", 0).like("name", pageBean.getQueryString()));
        return new PageResult(page.getTotal(), page.getRecords());
//        return this.list(new QueryWrapper<CheckItem>().like("name", name));
    }*/

    @Override
    public boolean deleteById(Long id) {
        CheckItem checkItem = baseMapper.selectById(id);
        if (checkItem != null)
            checkItem.setIs_delete(1);
        return updateById(checkItem);
    }

    @Override
    public List<CheckItem> findAll() {
        return this.list(new QueryWrapper<CheckItem>().eq("is_delete", 0));
    }

    @Override
    public PageResult findByPage(QueryPageBean pageBean) {
        IPage<CheckItem> page = new Page<>();
        if (pageBean.getQueryString() != null) {
            page = page(new Page<>(pageBean.getCurrentPage(), pageBean.getPageSize()), new QueryWrapper<CheckItem>().eq("is_delete", 0).like("name", pageBean.getQueryString()));

        } else {
            page = page(new Page<>(pageBean.getCurrentPage(), pageBean.getPageSize()), new QueryWrapper<CheckItem>().eq("is_delete", 0));

        }
        return new PageResult(page.getTotal(), page.getRecords());
    }
}
